<?php

namespace backend\models;

use Yii;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "tags".
 *
 * @property int $id
 * @property string $title 标签名
 * @property string $user_id 创建人
 * @property string $created_at 创建时间
 */
class Tags extends \yii\db\ActiveRecord
{
    public static function getDb()
    {
        return Yii::$app->get('forge');
    }
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tags';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id'], 'integer'],
            [['created_at'], 'safe'],
            [['title'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => '标签名',
            'user_id' => '创建人',
            'created_at' => '创建时间',
        ];
    }

    /**
     * @inheritdoc
     * @return TagsQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new TagsQuery(get_called_class());
    }

    public static function getAllTags()
    {
        return ArrayHelper::map(Tags::find()->where("`user_id`=0 OR `user_id`=" . Yii::$app->user->id)->all(), 'id', 'title');
    }

}
